#include "testwindow.h"
#include "ui_testwindow.h"



/**
 * @file testwindow.cpp
 * @author  Paweł Hanejko <phanejko@gmail.com>
 * @version 1.0
 *
 * @section LICENSE
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details at
 * http://www.gnu.org/copyleft/gpl.html
 *
 * @section DESCRIPTION
 * Plik źródłowy zawiera implementację okna identyfikacji biometrycznej
 *
 *
 */

inline bool same(QImage & a, QImage& b)
{
    return QImage(a) == QImage(b);

}

TestWindow::TestWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::TestWindow)
{
    ui->setupUi(this);

    QGraphicsView view(&scene);
    ui->graphicsView->setScene(&scene);
    ui->graphicsView->show();

}


inline bool TestWindow::identify(QImage & i1, QImage & i2,bool ( *compare)(QImage &, QImage&))
{
    return (*compare)(i1,i2);
}

bool TestWindow::test(QString file)
{
    QImage img(file);
    QPixmap pmap= QPixmap::fromImage(img);


    scene.addPixmap(pmap);

    QList<Person*>  *users= ((MainWindow*)parent())->users;

    foreach (Person* p,*users)
        foreach (QImage* i, p->images())
        {
            return identify(*i,img,same);
        }
}

TestWindow::~TestWindow()
{
    delete ui;
}
